﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    ViewBag.Title = "ZKTS";
    Layout = null;
}
@{
    if (Model.StandardConfig == null)
    { 
    <text>考核目标未配置</text>
        return;
    }
    List<dynamic> list = new List<dynamic>();
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {
        var query = Model.WMDayDatasHistory.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month);
        if (query == null )
        {
            list.Add(new
            {
                时间 = dt,
                考核目标 = Model.StandardConfig.一次修复率目标,
                一次修复率 = 0
            });
        }
        else
        {
            list.Add(new
            {
                时间 = dt,
                考核目标 = Model.StandardConfig.一次修复率目标,
                //K6/E6
                //四个月未回厂客户总数/(C6+D6-H6))
                //本月新增四个月未回厂数/(上月末分管客户总数+本月A卡转C卡客户数-六个月未回厂客户总数)
                一次修复率 = Model.GetAvgHistoryYCXHL(dt.Year,dt.Month)
            });
        }
    }

    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.IsRate = true;
    ChartModel.YAxis = "百分率";

    foreach (var item in list.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "考核目标";
    foreach (var item in list)
    {
        series.Data.Add(item.考核目标);
    }
    ChartModel.Serieses.Add(series);
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "一次修复率";
    foreach (var item in list)
    {
        series1.Data.Add(item.一次修复率);
    }
    ChartModel.Serieses.Add(series1);
}
<div style="height: 100%; overflow: auto">
    @Html.Action("ReportBar", "Common", Model.BarModel)
    <div style="position: relative; width: 100%">
        <div class="pagetitle">
            一次修复率对比</div>
        <table width="100%">
            <tr>
                <td style="width: 5%">
                    &nbsp;
                </td>
                <td valign="top" style="width:25%">
                    <p style=" padding-bottom:15px; font-size:15px;">@(Model.BarModel.Month.Month)月一次修复率</p>
                    <table class="reporttable" style="border-collapse: collapse;">
                        <thead>
                            <tr>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        车间主管姓名</div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        车间主管职业资质
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        交车后回厂返修总数
                                    </div>
                                </th>
                                <th class="tb_header_lightbluebg">
                                    <div>
                                        一次修复率
                                    </div>
                                </th>
                            </tr>
                        </thead>
                        @foreach (var item in Model.WMDayDatas.GroupBy(o => o.EmployeeId))
                        {
                            <tr>
                                <td>@item.FirstOrDefault().Employee.Name
                                </td>
                                <td>@(item.FirstOrDefault().Employee.WorkYear)年
                                </td>
                                <td>@item.Sum(o => o.JCHHCFXZS)
                                </td>
                                <td @if (Model.StandardConfig.一次修复率目标 > Model.GetYCXHL(item.Key, item.FirstOrDefault().AddTime.Year, item.FirstOrDefault().AddTime.Month))
                                    {
                                    <text> style="background:#ff1100"</text>
                                    }>@Model.GetYCXHL(item.Key, item.FirstOrDefault().AddTime.Year, item.FirstOrDefault().AddTime.Month)%
                                </td>
                            </tr>
                        }
                        <tr>
                            <td colspan="2">
                                车间平均数
                            </td>
                            <td>
                                @(Model.WMDayDatas.GroupBy(o => o.EmployeeId).Count()==0?0:Model.WMDayDatas.Sum(o => o.JCHHCFXZS) / Model.WMDayDatas.GroupBy(o => o.EmployeeId).Count())
                            </td>
                            <td>
                                @Model.GetAvgYCXHL(Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                考核目标
                            </td>
                            <td>
                            </td>
                            <td>
                                @if (Model.StandardConfig != null)
                                {
                                    @Math.Round(@Model.StandardConfig.一次修复率目标, 1)<text>%</text>
                                }
                            </td>
                        </tr>
        </table>
        </td>
        <td  style="width:70%">
            @Html.Partial("../Chart/Line", ChartModel)
        </td>
        </tr> </table>
    </div>
</div>
